//
//  WPHotTradeViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/3/31.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPHotTradeViewController.h"
#import "WPNewsDealingModel.h"
#import "WPNewsDealingTableViewCell.h"
#import "WPNewsPreheatModel.h"
#import "WPNewsPreheatTableViewCell.h"

@interface WPHotTradeViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIView * headView;/**< 交易人数背景图 */
@property (nonatomic, strong) UILabel * tradeCountIntrLabel;/**< 交易人数总计说明 */
@property (nonatomic, strong) UILabel * tradeCountLabel;/**< 交易人数总计 */
@property (nonatomic, strong) UITableView * hotTradeTableView;/**< 交易热区表格视图 */
@property (nonatomic, strong) NSMutableArray * hotTradeArr;/**< 交易热区数据源 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */


@end

@implementation WPHotTradeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.hotTradeArr = [NSMutableArray arrayWithCapacity:0];
    WPNewsPreheatModel * model = [WPNewsPreheatModel new];
    model.posterImageName = @"banner1.png";
    model.title = @"The squall Rain亚洲演唱会";
    model.detail = @"违法龙卷风甲方垃圾分类加了福建福利及发洛杉矶大连三姐夫龙卷风龙卷风垃圾按缴费卡九分裤积分卡了解封了案件发空间分类";
    model.attentionCount = @"40000";
    model.leftDays = @"12";
    
    WPNewsDealingModel * model1 = [WPNewsDealingModel new];
    model1.posterImageName = @"banner1.png";
    model1.title = @"The squall Rain亚洲演唱会";
    model1.detail = @"违法龙卷风甲方垃圾分类加了福建福利及发洛杉矶大连三姐夫龙卷风龙卷风垃圾按缴费卡九分裤积分卡了解封了案件发空间分类";
    model1.ticketCount = @"750";
    model1.allTicketCount = @"800";
    model1.joinCount = @"200";
    model1.leftDays = @"8";
    for (int i = 0; i < 2; i++) {
        [_hotTradeArr addObject:model];
    }
    [_hotTradeArr addObject:model1];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.headView];
    [self.view addSubview:self.hotTradeTableView];
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _hotTradeArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section != _hotTradeArr.count - 1) {
        WPNewsPreheatTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell) {
            cell = [[WPNewsPreheatTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"123"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        [cell setModelWithModel:_hotTradeArr[indexPath.section]];
        return cell;
    }
    WPNewsDealingTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[WPNewsDealingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"1234"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setModelWithModel:_hotTradeArr[indexPath.section]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 280*DHFlexibleHorizontalMutiplier();
}
//用户点击了某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
#pragma mark - getter
- (UIView *)headView {
    if (!_headView) {
        _headView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, 70*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = [UIColor whiteColor];
            [view addSubview:self.tradeCountIntrLabel];
            [view addSubview:self.tradeCountLabel];
            view;
        });
    }
    return _headView;
}
- (UILabel *)tradeCountIntrLabel {
    if (!_tradeCountIntrLabel) {
        _tradeCountIntrLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 10*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:16*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            UIView * leftLine = [[UIView alloc]initWithFrame:CGRectMake(60*DHFlexibleHorizontalMutiplier(), CGRectGetMidY(lab.bounds), 50*DHFlexibleHorizontalMutiplier(), 1)];
            leftLine.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            UIView * rightLine = [[UIView alloc]initWithFrame:CGRectMake(210*DHFlexibleHorizontalMutiplier(), CGRectGetMidY(lab.bounds), 50*DHFlexibleHorizontalMutiplier(), 1)];
            rightLine.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            [lab addSubview:leftLine];
            [lab addSubview:rightLine];
            lab.text = @"累计交易人数";
            lab;
        });
    }
    return _tradeCountIntrLabel;
}
- (UILabel *)tradeCountLabel {
    if (!_tradeCountLabel) {
        _tradeCountLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 30*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:16*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = COLOR_RGB(234, 27, 47, 1);
            lab.text = @"1 2 4 8 2 6 7";
            lab;
        });
    }
    return _tradeCountLabel;
}
- (UITableView *)hotTradeTableView {
    if (!_hotTradeTableView) {
        _hotTradeTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.headView.frame) + 10*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, SCREEN_SIZE.height - CGRectGetMaxY(self.headView.frame) - 10*DHFlexibleHorizontalMutiplier()) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.separatorColor = [UIColor clearColor];
            tableview;
        });
    }
    return _hotTradeTableView;
}

@end
